fix: rebuild Contact from public_address after 401 NAT challenge#107
Merged
shenjinti merged 1 commit intorestsend:mainfrom Mar 31, 2026
Merged
Conversation
After a 401 Unauthorized response, the Via rport/received parameters reveal the actual NAT-mapped source port, which may differ from the STUN-discovered port. The auth retry reused the original Contact with the stale port, causing registration to succeed but incoming requests to be routed to the wrong address. Now rebuilds the Contact header from the updated public_address after handle_client_authenticate, ensuring the retry uses the correct NAT mapping observed by the server. Also removes a duplicate rport push in handle_client_authenticate — get_via already adds rport, and duplicate Via params can cause some servers to silently drop the request.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
After a 401 Unauthorized response, the Via
rport/receivedparameters reveal the actual NAT-mapped source port, which may differ from the STUN-discovered port. The auth retry reused the original Contact with the stale port, causing registration to succeed but incoming requests to be routed to the wrong address.public_addressafterhandle_client_authenticate, so the retry uses the server-observed NAT mappingrportpush inhandle_client_authenticate—get_viaalready adds it, and duplicate Via params cause some servers to silently drop the requestProblem
public_ip:60537via STUN, sends REGISTER withContact: <sip:user@public_ip:60537>rport=16358;received=public_ip(actual source port differs from STUN)public_addressis updated topublic_ip:16358, but the auth retry clones the original request, keeping the stale Contactpublic_ip:60537Fix
After
handle_client_authenticatereturns the auth response, check ifpublic_addresswas updated and rebuild the Contact header with the corrected address before sending.Test plan